package com.dabbo.starship.client.listeners;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.rmi.RemoteException;

import com.dabbo.starship.app.client.StarShipMain;

public class GridViewerKeyListener implements KeyListener {

	private StarShipMain controlClient;
	
	public GridViewerKeyListener(StarShipMain controlClient) {
		this.controlClient = controlClient;
	}
	
	
	@Override
	public void keyPressed(KeyEvent event) {
		try {
			switch(event.getKeyCode()) {
				case 83:	// Key S
					this.controlClient.movePlayer(StarShipMain.MOVE_DOWN);
					break;
				case 65:	// Key A
					this.controlClient.movePlayer(StarShipMain.MOVE_LEFT);
					break;
				case 68:	// Key D
					this.controlClient.movePlayer(StarShipMain.MOVE_RIGHT);
					break;
				case 87:	// Key W
					this.controlClient.movePlayer(StarShipMain.MOVE_UP);
					break;
				case 69:	// Key E
					this.controlClient.activateCell();
					break;
				default:
					System.out.println("Unknown key press of : " + event.getKeyCode());
			}
		} catch (RemoteException ex) {
			System.out.println("Remote issue");
		}
	}

	@Override
	public void keyReleased(KeyEvent event) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void keyTyped(KeyEvent event) {
		// TODO Auto-generated method stub
		
	}

}
